﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace ServerTest
{
    class Program
    {
        static void Main(string[] args)
        {
            const int PORT = 1979;

            if (!Socket.OSSupportsIPv6)
            {
                Console.Error.WriteLine("Your system does not support IPv6\r\n" +
                    "Check you have IPv6 enabled and have changed machine.config");
                return;
            }
            Socket listener = new Socket(
                AddressFamily.InterNetworkV6,
                SocketType.Stream,
                ProtocolType.Tcp);
            try
            {
                listener.Bind(new IPEndPoint(IPAddress.IPv6Any, PORT));
                listener.Listen(0);
                Socket socket = listener.Accept();
                listener.Close();

                byte[] b = new byte[11];
                int len;
                while ((len = socket.Receive(b)) != 0)
                {
                    System.Console.WriteLine("RX: " +
                        System.Text.ASCIIEncoding.ASCII.GetString(b, 0, len));
                    b = new byte[11];
                }
                socket.Close();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
           
        }
    }
}
